﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using CustomException.Err;
using DBUtilities;
using DataAccess.Data;

namespace HrManager
{
    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (tbxUserCode.Text.Trim() == "")
            {
                BigMessageBox.Show("请您输入用户或密码！！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                this.tbxUserCode.Text = "";
                this.tbxUserCode.Text = "";
                this.tbxUserCode.Focus();
                return;
            }
            else
            {
                EmployeeInfo emp = null;
                switch (User.LoginValidate(tbxUserCode.Text.Trim(), tbxUserPwd.Text.Trim(), out emp))
                {
                    case User.LoginResult.NoUser:
                        {
                            BigMessageBox.Show("没有该用户信息", "用户验证", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            tbxUserCode.Text = "";
                            tbxUserCode.Focus();
                            break;
                        }
                    case User.LoginResult.PasswordError:
                        {
                            BigMessageBox.Show("用户密码错误！！", "用户验证", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            tbxUserPwd.Text = "";
                            tbxUserPwd.Focus();
                            break;
                        }
                    case User.LoginResult.Success:
                        {
                            FormMain objMain = new FormMain();
                            this.Hide();
                            objMain.Show();
                            break;
                        }
                    default:
                        break;
                }

            }
        }

        private void FormLogin_Load(object sender, EventArgs e)
        {
            tbxUserCode.Focus();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Dispose();
            GC.Collect();
            Application.Exit();
        }
    }
}